import { ElMessageBox, ElMessage } from "element-plus";
export const isEmpty = (val: unknown): boolean => {
	if (val === 0) return false;
	if (typeof val === "boolean") return false;
	if (Array.isArray(val)) return false;
	if (!val) return true;
	return typeof val === 'string' && /^\s*$/.test(val);
};

/**
 * 空对象判断
 * @param {*} obj
 * @returns {boolean}
 */
export const isEmptyObj = (obj:any) => {
	if (Object.prototype.toString.call(obj) !== "[object Object]") {
		return true;
	} else if (!Object.keys(obj).length) {
		return true;
	} else {
		return false;
	}
};

export const confirm = (cb, options: any = {}) => {
  const {
    message="确认删除吗？",
    title = "提示",
    confirmButtonText = "确定",
    cancelButtonText = "取消",
    type = "warning",
  } = options;
  ElMessageBox.confirm(message, title, {
    confirmButtonText,
    cancelButtonText,
    type,
  })
    .then(() => {
      cb && cb();
    })
    .catch(() => {});
};
export const showToast = (
  message: any = "",
  type: any = "error",
  duration: any = 3000,
  showClose: any = false,
  isHtml: any = false,
) => {
  // duration = themeInfo?.autoCloseMessage === "0" ? 0 : duration;
  ElMessage({
    message,
    type,
    duration,
    showClose: duration === 0 ? true : showClose,
    dangerouslyUseHTMLString: isHtml,
  });
};

export const html2Escape = (sHtml) => {
  return sHtml.replace(/[<>&"']/g, function (c) {
    return {
      "<": "&lt;",
      ">": "&gt;",
      "&": "&amp;",
      '"': "&quot;",
      "'": "&#39;",
    }[c];
  });
};